package com.linyaonan.leetcode.medium._155;

import java.util.LinkedList;

/**
 * @author: Lin
 * @date: 2024/9/28
 */
public class MinStack2 {

    LinkedList<Integer> org;
    LinkedList<Integer> min;

    public MinStack2() {
        org = new LinkedList<>();
        min = new LinkedList<>();
    }

    public void push(int val) {
        org.addFirst(val);
        if (min.isEmpty()) {
            min.addFirst(val);
        } else {
            min.addFirst(Math.min(min.peekFirst(), val));
        }
    }

    public void pop() {
        org.removeFirst();
        min.removeFirst();
    }

    public int top() {
        return org.peekFirst();
    }

    public int getMin() {
        return min.peekFirst();
    }

}
